﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using EvertonApp.Data.UnitOfWork;
using EvertonApp.Transporte;

namespace EvertonApp.WebAPI.Controllers
{
    public class NoticiaController : ApiController
    {
        private ForoUoW _foro;

        public NoticiaController()
        {
            this._foro = new ForoUoW();
        }

        // GET api/noticia
        public IEnumerable<Noticia> Get()
        {
            IQueryable<Noticia> noticias = _foro.NoticiasRepository.GetAll();

            return noticias.AsEnumerable();
        }

        // GET api/noticia/5
        public Noticia Get(Guid id)
        {
            return _foro.NoticiasRepository.GetById(id);
        }

        // POST api/noticia
        public Noticia Post([FromBody]Noticia value)
        {
           return _foro.NoticiasRepository.Insert(value);
        }

        // PUT api/noticia/5
        public bool Put(Guid id, [FromBody]Noticia value)
        {
           return _foro.NoticiasRepository.Update(id, value);
        }

        // DELETE api/noticia/5
        public bool Delete(Guid id)
        {
          return  _foro.NoticiasRepository.Delete(_foro.NoticiasRepository.GetById(id));
        }
    }
}
